package com.example.utils;

import org.springframework.beans.factory.annotation.Value;

import org.springframework.http.*;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author: 张比特
 * @Data: 2025/1/31 下午5:16
 * @Version: v1.0.0
 * @Description: TODO Falsk接口，当前版本已弃用
 **/
@Component
public class FalskClient {

    // Falsk接口的Url
    @Value("${falsk.url}")
    private String url;

    public ResponseEntity<String> test() {
        // 创建请求体
        Map<String, String> requestBody = new HashMap<>();
        requestBody.put("source", "example");

        // 设置请求头
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);

        // 创建 HTTP 实体
        HttpEntity<Map<String, String>> requestEntity = new HttpEntity<>(requestBody, headers);

        // 创建 RestTemplate
        RestTemplate restTemplate = new RestTemplate();

        // 发送 POST 请求
        ResponseEntity<String> response = restTemplate.exchange(
                url,
                HttpMethod.POST,
                requestEntity,
                String.class
        );

        // 打印响应
        System.out.println("Response Status: " + response.getStatusCode());
        System.out.println("Response Body: " + response.getBody());
        return response;
    }
}
